
function workerInfoOldCtrl($q, $rootScope, $scope, $http, ngDialog, paFetchService) {
  'ngInject';

  // 角色 1代表指挥部，2代表监理单位 3代表施工单位
  // $scope.$watch('workerInfo.selectItem', function(newValue) {
  //   this.selectItem = newValue;
  //   if (this.selectItem) {
  //     this.loginType = this.selectItem.orgType ? this.selectItem.orgType : 1;
  //   }
  // }.bind(this));
  this.loginType = 3;

  let isspecialMan = $state.params.isspecialMan; // 是否是特种人员
  let stationCategory = $state.params.stationCategory; // 岗位类别
  let stationCategoryText = $state.params.stationCategoryText;


  // 查询条件的对象
  this.userInfo = {
    isspecialMan: isspecialMan,
    status: isspecialMan != undefined || stationCategory != undefined ? 0 : undefined,
  };

  // 岗位类别
  if (stationCategoryText == '其他') {
    this.userInfo.workOtherType = stationCategory.split(',');
  } else {
    if (stationCategory) {
      this.userInfo.stationCategory = stationCategory;
    }
  }

  // 分页
  this.paginationData = {
    pageNum: 1,
    pageSize: 10,
    total: '',
  }

  this.beforeQuery4Department = () => {
    let _this = this;
    return paFetchService.getTeamWithOrgList()
            .then((respData) => {
              let teamsData = respData.data;
              let activeOrgId = $rootScope.activeBid.orgId;
              teamsData.forEach((org) => {
                if (org.orgUnitId == activeOrgId) {
                  org.teamList.forEach((team) => {
                    if (team.teamName == '项目部') {
                      _this.userInfo.constructionTeamId = team.teamId;
                    }
                  })
                }
              })
            })
  }

  this.beforeQuery4SpecialWorker = () => {
    let deferred = $q.defer()
    this.userInfo.isspecialMan = '1';
    deferred.resolve();
    return deferred.promise;
  }

  // 页码变化时调用方法
  $scope.pageChange = () => {
    // this.userInfo.orgId = $rootScope.activeBid.orgId;
    $http.post(`${SERVER_CONTEXT}/api/safesite/workerInfo/selectByPage`,
      angular.extend(this.userInfo, this.paginationData))
      .then((resp) => {
        this.workerItemList = resp.data.data;
        this.paginationData.total = resp.data.total;
    });
  };

  // 分页查询方法
  this.paginationQuery = () => {
    // this.userInfo.orgId = $rootScope.activeBid.orgId;
    $http.post(`${SERVER_CONTEXT}/api/safesite/workerInfo/selectByPage`,
      angular.extend(this.userInfo, this.paginationData)
        )
      .then((resp) => {
        this.workerItemList = resp.data.data;
        this.paginationData.total = resp.data.total;
    });
  };

  // 重置
  this.reset = () => {
    this.userInfo = {};
    this.userInfo.orgId = $rootScope.activeBid.orgId;
  }

  // 查询
  this.query = () => {
    this.paginationQuery();
  }

  let getSelectedWorkers = () => {
    let selectedWorkerList = [];
    let length = this.workerItemList.length;
    for (let i = 0; i < length; i++) {
      let item = this.workerItemList[i];
      if (item.checked) {
        selectedWorkerList.push(item);
      }
    }
    return selectedWorkerList;
  }

  // 查看
  this.goNewPage = (id) => {
    let url;
    if (this.loginType == 1) {
      url = $state.href('workerInfoDetailZhb',{id: id});
    }
    if (this.loginType == 2) {
      url = $state.href('workerInfoDetailZjb',{id: id});
    }
    if (this.loginType == 3) {
      url = $state.href('workerInfoDetail',{id: id});
    }
    window.open(url, '_blank');
  }

  // 离场登记
  this.forRegistration = () => {
    let selectedWorkerList = [], leaveTimeList = [], hasCheckedItem = false,
      shouldContinue = true;

    // 获得选中的人员
    let length = this.workerItemList.length;
    for (let i = 0; i < length; i++) {
      let item = this.workerItemList[i];
      if (item.checked) {
        shouldContinue = item.leaveTime ? false : true;
        selectedWorkerList.push(item);
      }
      if (!shouldContinue) {
        layer.alert('选择项内有已出场人员,请重新选择');
        return false;
      }
    }
    if (!selectedWorkerList.length) {
      layer.alert('请选择出场人员');
      return false;
    }

    $scope.selectedWorkerList = selectedWorkerList;
    $scope.leaveTimeList = leaveTimeList;

    let _this = this;
    ngDialog.openConfirm({
      template: 'workerExitDialog',
      className: 'ngdialog-theme-default pa-confirm-theme',
      scope: $scope,
      controllerAs: 'vm',
      controller: function($http, $scope) {
        'ngInject';
        this.submit = (param) => {
          // 修改表单是否提交过状态
          param.$submitted = true;

          // 表单校验
          if (param.$invalid) {
            return false;
          }

          let outPlantTime = this.outPlantTime;
          $scope.selectedWorkerList.forEach((item) => {
            item.leaveTime = outPlantTime;
            leaveTimeList.push(item.id);
          });

          let reqData = {
            ids : leaveTimeList,
            leaveTime : outPlantTime
          };

          if (_this.loginType == 1) {
            $http({
              method: 'post',
              url: `${SERVER_CONTEXT}/api/safesite/workerInfo/leaveSiteByZhb`,
              data: reqData,
            }).then((resp) => {
              if (resp.statusText == 'OK') {
                $scope.workerInfo.paginationQuery();
                $scope.closeThisDialog();
                layer.msg('出场成功');
              } else {
                $scope.closeThisDialog();
                layer.alert('服务器错误,请联系技术人员');
              }
            });
          }

          if (_this.loginType == 2) {
            $http({
              method: 'post',
              url: `${SERVER_CONTEXT}/api/safesite/workerInfo/leaveSiteByZjb`,
              data: reqData,
            }).then((resp) => {
              if (resp.statusText == 'OK') {
                $scope.workerInfo.paginationQuery();
                $scope.closeThisDialog();
                layer.msg('出场成功');
              } else {
                $scope.closeThisDialog();
                layer.alert('服务器错误,请联系技术人员');
              }
            });
          }

          if (_this.loginType == 3) {
            $http({
              method: 'post',
              url: `${SERVER_CONTEXT}/api/safesite/workerInfo/leavesite`,
              data: reqData,
            }).then((resp) => {
              if (resp.statusText == 'OK') {
                $scope.workerInfo.paginationQuery();
                $scope.closeThisDialog();
                layer.msg('出场成功');
              } else {
                $scope.closeThisDialog();
                layer.alert('服务器错误,请联系技术人员');
              }
            });
          }


        }
      },
    })
  };

  // 打印二维码
  this.printQrCode = () => {
    let selectedWorkerList = getSelectedWorkers();
    if (!selectedWorkerList.length) {
      layer.alert('请选择人员');
      return;
    }
    $scope.selectedWorkerList = selectedWorkerList;
    ngDialog.openConfirm({
      template: 'workerInfoQrCodePrintDialog',
      className: 'ngdialog-theme-default pa-confirm-theme',
      scope: $scope,
      controllerAs: 'vm',
      controller: function($scope) {
        'ngInject';

        this.print = () => {
          $('.qr-print').print({ globalStyles: false, timeout: 1200 });
        }

        this.getQrCodeSrc = (item) => {
          let qrContent = encodeURIComponent(`#/workerInfo/${item.id}`);
          let requestUrlStr =
          `${$scope.serverContext}/api/qr?size=160&code=${qrContent}`;
          return requestUrlStr;
        }
      },
    })
  }

  this.toggleAllFlag = false;

  // 全选
  this.toggleAll = () => {
    this.workerItemList.forEach((item) => {
      item.checked = this.toggleAllFlag;
    });
  }

  // 判断全选人
  this.isChange = () => {
    var bool = true;
    this.workerItemList.forEach((item) => {
      if(!item.checked){
        bool = false;
      }
    });
    this.toggleAllFlag = bool;
  }

  // 删除人员
  this.delete = (id) => {
    $scope.modalTitle = '删除人员';
    $scope.modalContent = '确认要删除该人员信息吗?';
    ngDialog.openConfirm({
      template: 'paConfirm',
      className: 'ngdialog-theme-default pa-confirm-theme',
      scope: $scope,
    }).
      then((value) => {
        if (this.loginType == 1) {
          $http.get(`${SERVER_CONTEXT}/api/safesite/workerInfo/deleteByZhb/${id}`).
            then((resp) => {
              if (resp.data.success) {
                layer.msg(resp.data.message);
                this.paginationQuery();
              } else {
                layer.alert(resp.data.message);
              }
            });
        }
        if (this.loginType == 2) {
          $http.get(`${SERVER_CONTEXT}/api/safesite/workerInfo/deleteByZjb/${id}`).
            then((resp) => {
              if (resp.data.success) {
                layer.msg(resp.data.message);
                this.paginationQuery();
              } else {
                layer.alert(resp.data.message);
              }
            });
        }
        if (this.loginType == 3) {
          $http.get(`${SERVER_CONTEXT}/api/safesite/workerInfo/delete/${id}`).
            then((resp) => {
              if (resp.data.success) {
                layer.msg(resp.data.message);
                this.paginationQuery();
              } else {
                layer.alert(resp.data.message);
              }
            });
        }

      }, (reason) => {});
  }

  // 升序、降序
  this.up = (param,index) => {
    this.userInfo.columeName = param;
    this.userInfo.order = index;
    this.paginationQuery();
  }

  // 初始化页面信息
  this.initPage = () => {
    // 获得施工队list
    paFetchService
      .getTeamWithOrgList()
      .then((resp) => {
        this.teamWithOrgList = resp.data;
      });
    // this.paginationQuery();
  }

  this.initPage();

}

export default workerInfoOldCtrl;